package com.vf.cloud.rendering.common.thread;

import java.util.Timer;
import java.util.TimerTask;

import com.vf.cloud.rendering.common.factory.UEFactory;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class UETimerTask extends TimerTask {

	private String id;
	private Timer timer;
	private int i = 0;
	private int timeout = 5;

	public UETimerTask(String id, Timer timer) {
		this.id = id;
		this.timer = timer;
	}

	@Override
	public void run() {
		if (UEFactory.getInstance().hasPlayerPross(id)) {
			i = 0;
		} else {
			if (i > timeout) {
				UEFactory.getInstance().killUEByEIO(id);
				timer.cancel();
				log.info("建立链接>>>" + id + "<<< 已超时，主动退出程序.");
			} else {
				log.info("等待建立链接>>>" + id + "<<< 超时剩余 >>>" + (timeout - i) + "<<<秒.");
				i++;
			}
		}
	}
}
